#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<list>
using namespace std;


struct listnode
{
    int val;
    listnode* next;
};

listnode* buynode(int x)
{
    listnode* p = new listnode;
    p->val = x;
    p->next = nullptr;
    return p;
}

void push_back(listnode* p, int x)
{
    listnode* tmp = buynode(x);
    tmp->next = p->next;
    p->next = tmp;
}

int _size(listnode* p)
{
    listnode* cur = p->next;
    int count = 0;
    while (cur != p)
    {
        cur = cur->next;
        count++;
    }
    return count + 1;
}

void build(listnode* p, int n)
{
    listnode* cur = p;
    for (int i = 1; i <= n; i++)
    {
        cur->val = i;
        cur = cur->next;
    }
}

listnode* erase(listnode* p)
{
    listnode* tmp = p->next;
    while (tmp->next != p)
    {
        tmp = tmp->next;
    }
    tmp->next = p->next;
    return tmp->next;
}

void change(listnode* p,int m)
{
    listnode* cur = p;
    while (_size(p) != 1)
    {
        for (int i = 0; i < m - 1; i++)
        {
            cur = cur->next;
        }
        cur = erase(cur);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    listnode p;
    p.val = 1;
    p.next = &p;
    for (int i = 2; i <= n; i++)
    {
        push_back(&p, i);
    }
    build(&p,n);
    change(&p, m);
    cout << p.val << endl;
    return 0;
}